package logic.nodes.damagable.shield;

import logic.nodes.BoundController;
import logic.nodes.damagable.DamagableNode;
import logic.ships.mothership.MotherShip;

import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.bounding.BoundingVolume;

public class ShieldBoundController extends BoundController {
	
	private static final long serialVersionUID = 1L;
	
	private DamagableNode node;
	
	public ShieldBoundController(DamagableNode node) {
		super(node);
		this.node = node;
		
		node.setModelBound(new BoundingSphere());
		node.updateModelBound();
		node.updateWorldBound();
	}
	
	private boolean msSpawnsReady() {
		if(node instanceof MotherShip) {
			MotherShip ms = (MotherShip)node;
			return ms.spawnsAreReady();
		}
		return true;
	}
	
	@Override
	protected boolean ready() {
		BoundingVolume volume = node.getWorldBound();
		return volume != null && volume instanceof BoundingSphere && msSpawnsReady();
	}
	
	@Override
	protected void performAction(float time) {
		BoundingVolume volume = node.getWorldBound();
		node.setShieldBound((BoundingSphere)volume.clone(null));
		node.setModelBound(new BoundingBox());
		node.updateModelBound();
		node.updateWorldBound();
	}
}